﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Text;

namespace ltModel.DAL
{
    /// <summary>
    ///xmsq 的摘要说明
    /// </summary>
    public class xmsq
    {
        public xmsq()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from lt_xmsq where id=" + id + "");
            return DataObject.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ltModel.Model.xmsq model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into lt_xmsq(");
            strSql.Append("sqdw,dwfzr,lxdh,phone,xmmc,xmfzr,dh,xmdd,xmsj,jfly,xmjf,sbxm,mingcheng,ip");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.sqdw + "',");
            strSql.Append("'" + model.dwfzr + "',");
            strSql.Append("'" + model.lxdh + "',");
            strSql.Append("'" + model.phone + "',");
            strSql.Append("'" + model.xmmc + "',");
            strSql.Append("'" + model.xmfzr + "',");
            strSql.Append("'" + model.dh + "',");
            strSql.Append("'" + model.xmdd + "',");
            strSql.Append("'" + model.xmsj + "',");
            strSql.Append("'" + model.jfly + "',");
            strSql.Append("'" + model.xmjf + "',");
            strSql.Append("'" + model.sbxm + "',");
            strSql.Append("'" + model.mingcheng + "',");
            strSql.Append("'" + model.ip + "'");
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DataObject.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ltModel.Model.xmsq model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_xmsq set ");
            if (model.sqdw != null)
                strSql.Append("sqdw='" + model.sqdw + "',");
            if (model.dwfzr != null)
                strSql.Append("dwfzr='" + model.dwfzr + "',");
            if (model.lxdh != null)
                strSql.Append("lxdh='" + model.lxdh + "',");
            if (model.phone != null)
                strSql.Append("phone='" + model.phone + "',");
            if (model.xmmc != null)
                strSql.Append("xmmc='" + model.xmmc + "',");
            if (model.xmfzr != null)
                strSql.Append("xmfzr='" + model.xmfzr + "',");
            if (model.xmdd != null)
                strSql.Append("xmdd='" + model.xmdd + "',");
            if (model.xmsj != null)
                strSql.Append("xmsj='" + model.xmsj + "',");
            if (model.jfly != null)
                strSql.Append("jfly='" + model.jfly + "',");
            if (model.xmjf != null)
                strSql.Append("xmjf='" + model.xmjf + "',");
            if (model.sbxm != null)
                strSql.Append("sbxm='" + model.sbxm + "',");
            if (model.dh != null)
                strSql.Append("dh='" + model.dh + "',");
            if (model.ip != null)
                strSql.Append("ip='" + model.ip + "'");
            
            strSql.Append(" where [id]=" + model.id + "");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 修改点击量
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public bool UpdateHits(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE lt_xmsq set hits=hits+1 ");
            strSql.Append("where id= " + id.ToString());
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_xmsq ");
            strSql.Append(" where id=" + id);
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        public bool Delete(string ids)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_xmsq ");
            strSql.Append(" where [id] in(" + ids + ")");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 审核消审操作
        /// </summary>
        /// <param name="ids">ID</param>
        /// <param name="zt">状态</param>
        /// <returns></returns>
        public bool UpdateZT(string ids, string zt)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_xmsq set ");
            strSql.Append(" zt = " + zt + "");
            strSql.Append(" where [id] in(" + ids + ")");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 公开取消公开操作
        /// </summary>
        /// <param name="ids">ID</param>
        /// <param name="zt">状态</param>
        /// <returns></returns>
        public bool UpdatePublic(string ids, string zt)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_xmsq set ");
            strSql.Append(" inpublic = " + zt + "");
            strSql.Append(" where [id] in(" + ids + ")");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ltModel.Model.xmsq GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append(" [id],[sqdw],[dwfzr],[lxdh],[phone],[xmmc],[xmfzr],[dh],[xmdd],[xmsj],[jfly],[xmjf],[sbxm],[ip]");
            strSql.Append(" from lt_xmsq ");
            strSql.Append(" where id=" + id);
            ltModel.Model.xmsq model = new ltModel.Model.xmsq();
            DataSet ds = DataObject.Query(strSql.ToString());
            model.id = id;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.sqdw = ds.Tables[0].Rows[0]["sqdw"].ToString();
                model.dwfzr = ds.Tables[0].Rows[0]["dwfzr"].ToString();
                model.lxdh = ds.Tables[0].Rows[0]["lxdh"].ToString();
                model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
                model.xmmc = ds.Tables[0].Rows[0]["xmmc"].ToString();
                model.xmfzr = ds.Tables[0].Rows[0]["xmfzr"].ToString();
                model.dh = ds.Tables[0].Rows[0]["dh"].ToString();
                model.xmdd = ds.Tables[0].Rows[0]["xmdd"].ToString();
                model.xmsj = ds.Tables[0].Rows[0]["xmsj"].ToString();
                model.jfly = ds.Tables[0].Rows[0]["jfly"].ToString();
                model.xmjf = ds.Tables[0].Rows[0]["xmjf"].ToString();
                model.sbxm = ds.Tables[0].Rows[0]["sbxm"].ToString();
               
                model.ip = ds.Tables[0].Rows[0]["ip"].ToString();
               
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[sqdw],[dwfzr],[lxdh],[phone],[xmmc],[xmfzr],[dh],[xmdd],[xmsj],[jfly],[xmjf],[sbxm],[ip] ");
            strSql.Append(" FROM lt_xmsq ");
            if (strWhere.Trim() != "")
            {

                strSql.Append(" where " + strWhere);
            }
            return DataObject.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// <param name="TopNum">记录数</param>
        /// <param name="strWhere">条件</param>
        /// </summary>
        public DataSet GetList(string TopNum, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (TopNum.Trim() != "" && Int32.Parse(TopNum) > 0)
                strSql.Append(" top " + TopNum + " ");
            strSql.Append(" [id],[sqdw],[dwfzr],[lxdh],[phone],[xmmc],[xmfzr],[dh],[xmdd],[xmsj],[jfly],[xmjf],[sbxm],[ip]");
            strSql.Append(" FROM lt_xmsq ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DataObject.Query(strSql.ToString());
        }

        #endregion  成员方法
    }
}